﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using SysRoutesMobile.ServiceReference1;

namespace SysRoutesMobile
{
    public partial class BuscarRota : PhoneApplicationPage
    {
        static ServiceReference1.Service1SoapClient ws = new ServiceReference1.Service1SoapClient();

        public BuscarRota()
        {
            InitializeComponent();
            LoadListPicker1();
            ws.ListarLinhaCompleted += Select;
            ws.ParadaSelectCompleted += BuscadorParada;
        }

        public void LoadListPicker1()
        {
            ws.ListarLinhaAsync();    
        }

        public void Select(object sender, ServiceReference1.ListarLinhaCompletedEventArgs e)
        {
            List<SysRoutesMobile.ServiceReference1.Linha> list = e.Result.ToList();
            foreach (SysRoutesMobile.ServiceReference1.Linha l in list)
            {
                listPicker1.Items.Add(l);
            }
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            int id0 = (listPicker1.SelectedItem as Linha).id_linha;
            ws.ParadaSelectAsync(id0);
        }

        public void BuscadorParada(object sender, ServiceReference1.ParadaSelectCompletedEventArgs e)
        {
            List<SysRoutesMobile.ServiceReference1.Parada> list = e.Result.ToList();
            String s1 = "Paradas:\n";

            foreach (Parada p in list)
            {
                s1 += p.nome + "\n";
            }

            MessageBox.Show(s1);
        }
    }
}